/*
 * @Author: 41
 * @Date: 2022-02-18 00:24:58
 * @LastEditors: lihao
 * @LastEditTime: 2022-03-06 16:01:27
 * @Description: 状态数据仓库
 */
// 1.定义状态容器和状态
// 2.修改容器中的state
// 3.仓库中的action的使用

import { defineStore } from 'pinia'
import { getSectionList } from '@/api/services/user.service.js';
// main相当于id
export const mainStore = defineStore('main', {
  state: () => {
    return {
      helloworld: 'hello world!',
      count: 0,
      phone: 11122223333,
      pageTitle: '首页',
      logState: false,
      searchDis: false,
      sectionList: [],
      wsMessage: null,
      wsTimer: null
    }
  },
  getters: {
    phoneHidden(state) {
      return state.phone.toString().replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
    }
  },
  actions: {
    changeState() {
      this.count++
    },
    logIn() {
      this.logState = true;
    },
    async loadSectionList() {
      let result = await getSectionList();
      let data = result.result
      let arr = []
      for (let key in data) {
        arr.push(data[key])
      }
      this.sectionList = arr
    },
  }
})